package com.tbit.uqbike.service.eventListener;

import com.alibaba.fastjson.JSON;
import com.tbit.uqbike.object.event.AccountConfigEvent;
import com.tbit.uqbike.service.business.OutAgeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 区域配置事件监听器
 *
 * @author <a href="mailto:liu.haoxiang@tbit.com.cn">BUGXiang</a>
 * @version 1.0
 * @since 2025-2-6
 */
@Component
@Slf4j
public class AccountConfigListener {

    @Resource
    private OutAgeService outageService;


    /**
     * 运营开关关闭后删除停运配置
     *
     * @param event event
     */
    @EventListener
    public void onAccountConfigEvent(AccountConfigEvent event) {
        log.info("AccountConfigListener.onAccountConfigEvent {}", JSON.toJSONString(event));
        Integer accountId = event.getAccountId();
        if (Objects.nonNull(accountId)) {
            outageService.deleteByAccountId(null, accountId);
        }
    }
}
